load("@rules_cc//cc:cc_test.bzl", "cc_test")
load("@rules_cc//cc:defs.bzl", "cc_library")
load("@rules_license//rules:license.bzl", "license")

package(
    default_applicable_licenses = [":license"],
    default_visibility = ["//visibility:public"],
)

exports_files(["LICENSE"])

licenses(["notice"])

license(
    name = "license",
    package_name = "roboticslibrary",
    license_kinds = [
        "@rules_license//licenses/spdx:BSD-2-Clause",
    ],
    license_text = "LICENSE",
)

cc_library(
    name = "math",
    hdrs = glob(
        ["src/rl/math/**/*.h*"],
        exclude = [
            "src/rl/math/*Addons.h",
            "src/rl/math/metrics/*.h",
            "src/rl/math/spatial/*.hxx",
        ],
    ),
    copts = [
        "-Wno-unused-variable",
        "-fexceptions",
    ],
    includes = ["src"],
    textual_hdrs = glob(["src/rl/math/**/*.h*"]),
    deps = [
        "@boost.optional",
        "@eigen",
    ],
)

cc_library(
    name = "util",
    srcs = glob(["src/rl/util/*.cpp"]),
    hdrs = glob(["src/rl/util/*.h"]),
    copts = ["-fexceptions"],
    includes = ["src"],
)

cc_library(
    name = "hal",
    srcs = glob(
        ["src/rl/hal/*.cpp"],
        exclude = [
            "src/rl/hal/Ati.cpp",
            "src/rl/hal/HilscherCifx.cpp",
            "src/rl/hal/Comedi.cpp",
            "src/rl/hal/Jr3.cpp",
            "src/rl/hal/Dc1394Camera.cpp",
        ],
    ),
    hdrs = glob(
        ["src/rl/hal/*.h"],
        exclude = [
            "src/rl/hal/Ati.h",
            "src/rl/hal/HilscherCifx.h",
            "src/rl/hal/Comedi.h",
            "src/rl/hal/Jr3.h",
            "src/rl/hal/Dc1394Camera.h",
        ],
    ),
    copts = [
        "-Wno-return-type",
        "-Wno-sign-compare",
        "-Wno-unused-variable",
        "-Wno-overloaded-virtual",
        "-Wno-implicit-fallthrough",
        "-DHAVE_LITTLE_ENDIAN",  # We assume x86.
        "-fexceptions",
    ],
    includes = ["src"],
    deps = [
        ":math",
        "@boost.algorithm",
        "@boost.dynamic_bitset",
        "@boost.iostreams",
        "@boost.lexical_cast",
        "@boost.optional",
    ],
)

cc_library(
    name = "mdl",
    srcs = glob(
        ["src/rl/mdl/*.cpp"],
        exclude = [
            "src/rl/mdl/NloptInverseKinematics.cpp",
            "src/rl/mdl/XmlFactory.cpp",
            "src/rl/mdl/UrdfFactory.cpp",
        ],
    ),
    hdrs = glob(
        ["src/rl/mdl/*.h"],
        exclude = [
            "src/rl/mdl/NloptInverseKinematics.h",
            "src/rl/mdl/XmlFactory.h",
            "src/rl/mdl/UrdfFactory.h",
        ],
    ),
    copts = [
        "-Wno-sign-compare",
        "-fexceptions",
    ],
    defines = ["RL_BUILD_MDL_NLOPT=0"],
    includes = ["src"],
    deps = [
        ":math",
        "@abseil-cpp//absl/container:node_hash_map",
        "@abseil-cpp//absl/container:node_hash_set",
        "@abseil-cpp//absl/log",
        "@boost.algorithm",
        "@boost.graph",
        "@boost.lexical_cast",
    ],
)

# Functionality Tests
cc_test(
    name = "rlCircularTest",
    srcs = ["tests/rlCircularTest/rlCircularTest.cpp"],
    deps = [":math"],
)

cc_test(
    name = "rlMathDeltaTest",
    srcs = ["tests/rlMathDeltaTest/rlMathDeltaTest.cpp"],
    deps = [":math"],
)

cc_test(
    name = "rlEuclideanCrossProductTest",
    srcs = ["tests/rlSpatialTest/rlEuclideanCrossProductTest.cpp"],
    deps = [":math"],
)

cc_test(
    name = "rlSpatialArticulatedBodyInertiaTest",
    srcs = ["tests/rlSpatialTest/rlSpatialArticulatedBodyInertiaTest.cpp"],
    deps = [":math"],
)

cc_test(
    name = "rlSpatialCrossProductTest",
    srcs = ["tests/rlSpatialTest/rlSpatialCrossProductTest.cpp"],
    deps = [":math"],
)

cc_test(
    name = "rlSpatialDotProductTest",
    srcs = ["tests/rlSpatialTest/rlSpatialDotProductTest.cpp"],
    deps = [":math"],
)

cc_test(
    name = "rlSpatialForceVectorTest",
    srcs = ["tests/rlSpatialTest/rlSpatialForceVectorTest.cpp"],
    deps = [":math"],
)

cc_test(
    name = "rlSpatialMotionVectorTest",
    srcs = ["tests/rlSpatialTest/rlSpatialMotionVectorTest.cpp"],
    deps = [":math"],
)

cc_test(
    name = "rlSpatialPlueckerTransformTest",
    srcs = ["tests/rlSpatialTest/rlSpatialPlueckerTransformTest.cpp"],
    deps = [":math"],
)

cc_test(
    name = "rlSpatialRigidBodyInertiaTest",
    srcs = ["tests/rlSpatialTest/rlSpatialRigidBodyInertiaTest.cpp"],
    deps = [":math"],
)

cc_test(
    name = "rlPolynomialExtremaTest",
    srcs = ["tests/rlSplineTest/rlPolynomialExtremaTest.cpp"],
    deps = [":math"],
)

cc_test(
    name = "rlPolynomialTest",
    srcs = ["tests/rlSplineTest/rlPolynomialTest.cpp"],
    deps = [":math"],
)

cc_test(
    name = "rlQuarticLinearQuarticTest",
    srcs = ["tests/rlSplineTest/rlQuarticLinearQuarticTest.cpp"],
    deps = [":math"],
)

cc_test(
    name = "rlSexticLinearSexticTest",
    srcs = ["tests/rlSplineTest/rlSexticLinearSexticTest.cpp"],
    deps = [":math"],
)

cc_test(
    name = "rlSplineScaleTest",
    srcs = ["tests/rlSplineTest/rlSplineScaleTest.cpp"],
    deps = [":math"],
)

cc_test(
    name = "rlSplineTest",
    srcs = ["tests/rlSplineTest/rlSplineTest.cpp"],
    deps = [":math"],
)

cc_test(
    name = "rlTrapezoidalAccelerationTest",
    srcs = ["tests/rlSplineTest/rlTrapezoidalAccelerationTest.cpp"],
    deps = [":math"],
)

cc_test(
    name = "rlHalEndianTest",
    srcs = ["tests/rlHalEndianTest/rlHalEndianTest.cpp"],
    deps = [":hal"],
)
